import Api from 'Api/index';
import appConfig from 'AppConfig/index';
import * as common from "Commons/index";
import globalBehavior from 'Behaviors/global';

let interstitialAd = null;

Page({
    behaviors: [globalBehavior],
	data: {
		today: "",
		jijinShow: false,
		bannerList: [{
			name: "",
			img_url: "https://lzhsus.oss-cn-beijing.aliyuncs.com/H_xxdyy/banner/267f9e2f0708283870a8c292d02fbe044e08f1ce.jpeg?x-oss-process=style/images_50",
			path: ""
		}],
		entranceList: [{
			id: 1,
			name: "停车码",
			link: "/pages/mobile/mobile",
		}, {
			id: 2,
			name: "地铁数据",
			link: "/pages/metro/metro",
		}, {
			id: 3,
			name: "光波",
			link: "/pages/light-wave/light-wave",
		}, {
			id: 4,
			name: "告白小人",
			link: "/package/confession-person/index/index",
		}, {
			id: 5,
			name: "表情包",
			link: "/package/emoji/index/index",
		}, {
			id: 6,
			name: "AI制图",
			link: "",
		}, {
			id: 7,
			name: "模卡 卡萌",
			link: "/package/model-card/index/index",
		}, {
			id: 8,
			name: "小游戏/工具",
			link: "/pages/game/game",
		}]
	},
	bindgetphonenumber(e) {

	},
	async onLoad(options) {
		this.initAD()
		this.getUserInfo()
	},
	getUserInfo(){
		Api.userinfo().then(res=>{
			if( res.success ){
				res = res.result||{};
				if( res.isAdmin ){
					let list = this.data.entranceList.map(item => {
						if (item.id == 7) {
							item.name = "基金";
							item.link = "/funds/index/index";
						}
						return item;
					})
					this.setData({
						entranceList: list
					})
				}
			}
		})
	},
	// 入口
	openEntranceClick(e) {
		let { item } = e.currentTarget.dataset || {};
		if (!item.link) {
			wx.showModal({
				content: "更多精彩，敬请期待~",
				showCancel: false
			})
			return
		}
		wx.navigateTo({
			url: item.link
		})
	},
	initAD() {
		// 在页面中定义插屏广告
		// 在页面onLoad回调事件中创建插屏广告实例
		if (wx.createInterstitialAd) {
			interstitialAd = wx.createInterstitialAd({
				adUnitId: 'adunit-fe4704d84f0d7d7c'
			})
			interstitialAd.onLoad(() => {
				console.log('插屏 广告加载成功-fe4704d84f0d7d7c')
			})
			interstitialAd.onError((err) => {
				console.log('插屏 广告加载失败' + err)
			})
			interstitialAd.onClose(() => {
				console.log('插屏 广告关闭')
			})
		}

		// 在适合的场景显示插屏广告
		if (interstitialAd) {
			interstitialAd.show().catch((err) => {
				console.error(err)
			})
		}
	},
	adLoad() {
		console.log('Banner 广告加载成功')
	},
	adError(err) {
		console.log('Banner 广告加载失败', err)
	},
	adClose() {
		console.log('Banner 广告关闭')
	},
	onShareAppMessage(res) {
		let shareObj = {
			title: "从未放弃，无所畏惧的你！",
			imageUrl: "https://aigc-t2p.cdn.bcebos.com/artist-long/12556736_0_final.png?md5hash=55aa4611c8611982ecad277e653f6d78&timestamp=1686902991&x-bce-process=style%2Fr_l",
			path: "/pages/home/home",
		}
		console.log(shareObj)
		return shareObj;
	}
})